import { ATeamCombat } from "GameLoop/WorldState/EntityManager/Entitys";
import { CacheDataHostiles } from "GameLoop/WorldState/PollingStation/PollingTasks/RoomItem/CacheHostiles";
import { destoryPriority } from "utils/constants/priorityconstant";
import { PositionHelper } from "utils/position/PositionHelper";
import { IDefendStrategy } from "./Strategys/Base";
import { DefendStrategy1 } from "./Strategys/DefendStrategy1";
import { DefendStrategy2 } from "./Strategys/DefendStrategy2";
import { DefendStrategy3 } from "./Strategys/DefendStrategy3";
import { DefendStrategy4 } from "./Strategys/DefendStrategy4";
import { DefendStrategy5 } from "./Strategys/DefendStrategy5";
import { ETaskState } from "GameLoop/DecisionMaking/TaskDeclare/type";
 
/**
 * 攻击策略
 */ 
export class  DefendStrategy
{
    private static strategy:Record<string,IDefendStrategy>={
        "sourceroom": new DefendStrategy1(),
        "normal": new DefendStrategy2(),
        "nineroom": new DefendStrategy3(),
        "hallway": new DefendStrategy4(),
        "destory":new DefendStrategy5(),
    }
    /**
     * 更新策略
     * @param room 
     * @param task 
     */ 
    public static updateTarget(room:Room,task:ITask<ITeamTaskData<"defend">>)
    {
       
        if(!task.data.arg.strategy)
        {
            const workRoomType = Memory.rooms[task.data.room]?.config?.type;
            if(workRoomType == 3)
            {
                task.data.arg.strategy='sourceroom';
            }
            else if(workRoomType == 6)
            {
                task.data.arg.strategy='nineroom';
            }
            else if(workRoomType == 5)
            {
                task.data.arg.strategy='hallway';
            }
            else 
            {
                task.data.arg.strategy='normal';
            }
            
        }

        const  strategy = this.strategy[task.data.arg.strategy];
        if(strategy)
        {

            const teams = _.flatten( Object.values(task.data.teams).map(e =>e.map(id=>  room.getEntityByID (id) as ATeamCombat)));
            const creeps =  task.data.creeps.map(e =>Game.creeps[e]).filter(e=>e);
            return strategy.assignTarget(room,task,teams,creeps);
        }
        return ETaskState.Complete;
    }
}